package com.kjlink.widget.monitoring.entity;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * 描述:
 *    实体基类：包含通用的ID定义（32位UUID）
 * @author Vic.xu
 * @since 2025-08-12 10:39
 */
@Getter
@Setter
// 标识为父类，不生成独立表，字段会被子类继承
@MappedSuperclass
// 审计监听器，放在父类即可
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID：32位无连字符UUID
     */
    @Id
    @GeneratedValue(generator = "custom-uuid")
    @GenericGenerator(name = "custom-uuid", strategy = "com.kjlink.widget.monitoring.util.CustomUUIDGenerator")
    @Column(name = "ID", length = 32, nullable = false, updatable = false)
    private String id;

    /**
     * 创建时间（首次保存时自动设置）
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 修改时间（每次更新时自动更新）
     */
    @LastModifiedDate
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 创建人
     */
    @Column(name = "CREATED_BY", length = 64)
    protected String createdBy;

    public BaseEntity() {
    }

}
